import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { rules } from '/@/utils/helper/validator';
import { defHttp } from '/@/utils/http/axios';
import { UploadTypeEnum } from '/@/components/Form/src/jeecg/components/JUpload';
import { render, formattingMin, formattingDay, formatTimestamp } from '/@/utils/common/renderUtils';
//列表数据
export const columns : BasicColumn[] = [
  /* 	{
      title: '类型',
      align: "center",
      dataIndex: 'type'
    }, */
  {
    title: '报名截止日期',
    align: "center",
    dataIndex: 'expiredate',
    customRender: ({ text }) => {
      return formatTimestamp(text)
    }
  },
  {
    title: '创建时间',
    align: "center",
    dataIndex: 'createtime',
    customRender: ({ text }) => {
      return formattingMin(text)
    }
  },
  {
    title: '状态',
    align: "center",
    dataIndex: 'stats',
    customRender: ({ text }) => {

      if (text == 'WaitOwner') {
        return '待创建人付款'
      } else if (text == 'Freze') {
        return '不可报名'
      } else if (text == 'Trash') {
        return '删除'
      } else if (text == 'Wait') {
        return '报名中'
      } else if (text == 'ApplyOk') {
        return '已成团'
      } else if (text == 'Cancel') {
        return '取消'
      } else if (text == 'TravelOver') {
        return '行程结束'
      } else if (text == 'AlreadyFull') {
        return '已满团'
      } else if (text == 'ApplyForDrawback') {
        return '申请取消行程'
      }
 
    }
  },
  {
    title: '调度状态',
    align: "center",
    dataIndex: 'dispatchstats',
    customRender: ({ text }) => {
      if (text == 'Audit') {
        return '待调度'
      } else if (text == 'Finished') {
        return '调度完成'
      } else if (text == 'Cancel') {
        return '取消'
      }
    }
  },
  {
    title: '行程标题',
    align: "center",
    dataIndex: 'traveltitle'
  },
  /* 	{
      title: '创建用户',
      align: "center",
      dataIndex: 'createuserid',
      customRender: ({ text }) => {
        if (text == 0) {
          return '后台创建'
        }
      }
    }, */
  /* 	{
      title: '游玩景点',
      align: "center",
      dataIndex: 'pretravellineid',
      customRender:({text})=>{
      	
      }
    }, */
  /* {
    title: '租户ID',
    align: "center",
    dataIndex: 'tenantid'
  }, */
  {
    title: '出发日期',
    align: "center",
    dataIndex: 'startdate',
    customRender: ({ text }) => {
      let o = formatTimestamp(text);
      return o.split(" ")[0]
    }
  },
  {
    title: '游玩天数',
    align: "center",
    dataIndex: 'travelDays'
  },
  {
    title: '成团人数',
    align: "center",
    dataIndex: 'extInfor',
    customRender: ({ text }) => {
      return JSON.parse(text).groupUserSize
    }
  },
  {
    title: '最大人数',
    align: "center",
    dataIndex: 'maxUserNum'
  },
  {
    title: '虚拟报名人数',
    align: "center",
    dataIndex: 'extInfor',
    customRender: ({ text }) => {
      return JSON.parse(text).virtualUserNum || 0
    }
  },
  {
    title: '已报名人数',
    align: "center",
    dataIndex: 'signUpUserNum',
  },
  {
    title: '候补人数',
    align: "center",
    dataIndex: 'beaCandidateUserNum',
  },
  {
    title: '合同ID',
    align: "center",
    dataIndex: 'contractid'
  },
  {
    title: '保险ID',
    align: "center",
    dataIndex: 'insuranceid'
  },


  {
    title: '备注',
    align: "center",
    dataIndex: 'remark'
  },

  /* {
    title: '预选车辆',
    align: "center",
    dataIndex: 'pretravelcarlist'
  }, */
  /* 	{
      title: '旅游路线，json',
      align: "center",
      dataIndex: 'travellineremark'
    }, */
];
//查询数据
export const searchFormSchema : FormSchema[] = [

  /* 	{
       label: '大团',
       field: 'maxGroupId',
       component: 'JSearchSelect',
       componentProps: {
         dict: 'BS_TravelGroup_TraveListGroup,titleGroup.mainTitle,id',
         async:true,
         pageSize:10
       },
     }, */

  {
    label: '标题',
    field: 'traveltitle',
    component: 'Input',
  },
  {
    label: '游玩天数',
    field: 'traveldays',
    component: 'InputNumber',
  },
  {
    label: '行程状态',
    field: 'stats',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'stroke_state'
    },

  },
];
//表单数据
export const formSchema : FormSchema[] = [
  /* 	{
      label: '类型',
      field: 'type',
      component: 'Input',
      dynamicRules: ({ model, schema }) => {
        return [
          { required: true, message: '请输入类型!' },
        ];
      },
    }, */
  {
    label: '行程状态',
    field: 'stats',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'stroke_state'
    },
    dynamicRules: ({ model, schema }) => {
      return [
        { required: true, message: '请输入创建状态!' },
      ];
    },
  },
  /* 	{
      label: '调度状态',
      field: 'dispatchstats',
      component: 'Input',
      dynamicRules: ({ model, schema }) => {
        return [
          { required: true, message: '请输入调度状态!' },
        ];
      },
    }, */
  /* {
    label: '创建用户ID',
    field: 'createuserid',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [
        { required: true, message: '请输入创建用户ID!' },
      ];
    },
  }, */
  {
    label: '旅游天数',
    field: 'travelDays',
    component: 'InputNumber',
    dynamicRules: ({ model, schema }) => {
      return [
        { required: true, message: '请输入旅游天数!' },
      ];
    },
    dynamicDisabled: true
  },
  /* 	{
      label: '预设路线ID',
      field: 'pretravellineid',
      component: 'Input',
      dynamicRules: ({ model, schema }) => {
        return [
          { required: true, message: '请输入预设路线ID!' },
        ];
      },
    }, */

  /* 	{
      label: '租户ID',
      field: 'tenantid',
      component: 'Input',
      dynamicRules: ({ model, schema }) => {
        return [
          { required: true, message: '请输入租户ID!' },
        ];
      },
    }, */
  {
    label: '出发日期',
    field: 'startdateStr',
    component: 'DatePicker',
    dynamicRules: ({ model, schema }) => {
      return [
        { required: true, message: '请选择出发日期!' },
      ];
    },
  },

  /* 	{
      label: '最大人数',
      field: 'maxUserNum',
      component: 'InputNumber',
      dynamicRules: ({ model, schema }) => {
        return [
          { required: true, message: '请输入最大人数!' },
        ];
      },
    },
    {
      label: '成团人数',
      field: 'groupUserSize',
      component: 'InputNumber',
      dynamicRules: ({ model, schema }) => {
        return [
          { required: true, message: '请输入成团人数!' },
        ];
      },
    }, */
  /* 	{
      label: '虚拟报名人数',
      field: 'virtualUserNum',
      component: 'InputNumber',
      dynamicRules: ({ model, schema }) => {
        return [
          { required: true, message: '请输入虚拟报名人数!' },
        ];
      },
    }, */
  {
    label: '合同',
    field: 'contractid',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [
        { required: true, message: '请输入合同ID!' },
      ];
    },
    dynamicDisabled: true
  },
  {
    label: '保险',
    field: 'insuranceid',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [
        { required: true, message: '请输入保险ID!' },
      ];
    },
    dynamicDisabled: true
  },
  {
    label: '报名截止时间',
    field: 'expiredateStr',
    component: 'DatePicker',
    componentProps: {
      showTime: true,
      valueFormat: 'YYYY-MM-DD HH:mm:ss'
    },
    dynamicRules: ({ model, schema }) => {
      return [
        { required: true, message: '请输入报名截止日期!' },
      ];
    },
  },

  /* {
    label: '行程标题',
    field: 'traveltitle',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [
        { required: true, message: '请输入旅游标题!' },
      ];
    },
  }, */
  /* {
    label: '备注',
    field: 'remark',
    component: 'InputTextArea',
    dynamicRules: ({ model, schema }) => {
      return [
        { required: true, message: '请输入备注!' },
      ];
    },
  }, */
  /* 	{
      label: '其他信息',
      field: 'extinfor',
      component: 'InputTextArea',
      dynamicRules: ({ model, schema }) => {
        return [
          { required: true, message: '请输入其他信息!' },
        ];
      },
    }, */
  /* 	{
      label: '预选车辆',
      field: 'pretravelcarlist',
      component: 'InputTextArea',
      dynamicRules: ({ model, schema }) => {
        return [
          { required: true, message: '请输入预选车辆!' },
        ];
      },
    }, 
    {
      label: '旅游路线',
      field: 'travellineremark',
      component: 'InputTextArea',
      dynamicRules: ({ model, schema }) => {
        return [
          { required: true, message: '请输入旅游路线!' },
        ];
      },
    },*/
  // TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false
  },
  {
    label: '',
    field: 'extInfor',
    component: 'Input',
    show: false
  },
];
/***
拼车
*/
//列表数据
export const columnsSelf : BasicColumn[] = [
  /* 	{
      title: '类型',
      align: "center",
      dataIndex: 'type'
    }, */
  {
    title: '报名截止时间',
    align: "center",
    dataIndex: 'expiredate',
    customRender: ({ text }) => {
      return formatTimestamp(text)
    }
  },
  {
    title: '创建时间',
    align: "center",
    dataIndex: 'createtime',
    customRender: ({ text }) => {
      return formattingMin(text)
    }
  },
  {
    title: '创建状态',
    align: "center",
    dataIndex: 'stats',
    customRender: ({ text }) => {

      if (text == 'WaitOwner') {
        return '待创建人付款'
      } else if (text == 'Freze') {
        return '不可报名'
      } else if (text == 'Trash') {
        return '删除'
      } else if (text == 'Wait') {
        return '报名中'
      } else if (text == 'ApplyOk') {
        return '报名完成'
      } else if (text == 'Cancel') {
        return '取消'
      } else if (text == 'TravelOver') {
        return '行程结束'
      }

    }
  },
  {
    title: '调度状态',
    align: "center",
    dataIndex: 'dispatchstats',
    customRender: ({ text }) => {
      if (text == 'Audit') {
        return '待调度'
      } else if (text == 'Finished') {
        return '调度完成'
      } else if (text == 'Cancel') {
        return '取消'
      }
    }
  },
  {
    title: '行程标题',
    align: "center",
    dataIndex: 'traveltitle'
  },
  {
    title: '游玩天数',
    align: "center",
    dataIndex: 'traveldays'
  },

  /* 	{
      title: '预设路线',
      align: "center",
      dataIndex: 'travellineremark'
    }, */

  /* 	{
      title: '创建用户',
      align: "center",
      dataIndex: 'createuserid',
      customRender: ({ text }) => {
        if (text == 0) {
          return '后台创建'
        }
      }
    }, */
  /* 	{
      title: '游玩景点',
      align: "center",
      dataIndex: 'pretravellineid',
      customRender:({text})=>{
      	
      }
    }, */
  /* {
    title: '租户ID',
    align: "center",
    dataIndex: 'tenantid'
  }, */
  {
    title: '出发日期',
    align: "center",
    dataIndex: 'startdate',
    customRender: ({ text }) => {
      let o = formatTimestamp(text);
      return o.split(" ")[0]
    }
  },

  {
    title: '最大人数',
    align: "center",
    dataIndex: 'maxusernum'
  },
  {
    title: '合同ID',
    align: "center",
    dataIndex: 'contractid'
  },
  {
    title: '保险ID',
    align: "center",
    dataIndex: 'insuranceid'
  },


  {
    title: '备注',
    align: "center",
    //dataIndex: 'remark'
    dataIndex: 'extinfor',
    customRender: ({ text }) => {
      return JSON.parse(text).remark
    }
  },
  {
    title: '成团人数',
    align: "center",
    dataIndex: 'extinfor',
    customRender: ({ text }) => {
      return JSON.parse(text).groupUserSize
    }

  },
  /* {
    title: '预选车辆',
    align: "center",
    dataIndex: 'pretravelcarlist'
  }, */
];
//表单数据--拼车发起
export const formSchemaSelf : FormSchema[] = [
  /* 	{
      label: '类型',
      field: 'type',
      component: 'Input',
      dynamicRules: ({ model, schema }) => {
        return [
          { required: true, message: '请输入类型!' },
        ];
      },
    }, */

  {
    label: '行程标题',
    field: 'traveltitle',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [
        { required: true, message: '请输入行程标题!' },
      ];
    },
  },
  {
    label: '行程状态',
    field: 'stats',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'stroke_state'
    },
    dynamicRules: ({ model, schema }) => {
      return [
        { required: true, message: '请选择行程状态!' },
      ];
    },
  },
  {
    label: '出发城市',
    field: 'cityId',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'sys_category,name,city_id,pid="1760922454642933761"'
    },
    dynamicRules: ({ model, schema }) => {
      return [
        { required: true, message: '请选择出发城市。!' },
      ];
    },
    /* dynamicDisabled: ({ values }) => {
      return values.isUpdate == true
    }, */
  },
  {
    label: '目的地景点',
    field: 'destination',
    component: 'JSearchSelect',
    componentProps: {
      dict: 'BS_Scenic,title,id',
      pageSize: 10,
      async: true
    },
    dynamicRules: ({ model, schema }) => {
      return [
        { required: true, message: '请选择目的地景点。!' },
      ];
    },
    /* dynamicDisabled: ({ values }) => {
      return values.isUpdate == true
    }, */
  },
  /* 	{
      label: '调度状态',
      field: 'dispatchstats',
      component: 'Input',
      dynamicRules: ({ model, schema }) => {
        return [
          { required: true, message: '请输入调度状态!' },
        ];
      },
    }, */
  {
    label: '增值服务类别',
    field: 'keyCode',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: "pdt_category"
    },
    required: true,
    dynamicRules: ({ model, schema }) => {
      return [
        { required: true, message: '请选择绑定产品类别。!' },
      ];
    },

  },
  {
    label: '创建用户',
    field: 'createuserid',
    component: 'JSearchSelect',
    componentProps: {
      dict: 'BS_UserLayout_UserInfor,phone,id',
      pageSize: 10
    },
    /* 	dynamicRules: ({ model, schema }) => {
        return [
          { required: true, message: '请输入创建用户ID!' },
        ];
      }, */
  },
  {
    label: '发起人说',
    field: 'fqrContent',
    component: 'InputTextArea',
    /* dynamicRules: ({ model, schema }) => {
      return [
        { required: true, message: '请输入发起人说!' },
      ];
    }, */
  },
  {
    label: '发起人图片',
    field: 'fqrImages',
    component: 'JUpload',
    helpMessage: '最多上传20张图片',
    componentProps: {
      fileType: UploadTypeEnum.image,
      maxCount: 20,
    },
    /* 	dynamicRules: ({ model, schema }) => {
        return [
          { required: true, message: '请输入发起人说!' },
        ];
      }, */
  },
  {
    label: '游玩天数',
    field: 'travelDays',
    component: 'InputNumber',
    dynamicRules: ({ model, schema }) => {
      return [
        { required: true, message: '请输入游玩天数!' },
      ];
    },
    //	dynamicDisabled: true
  },
  {
    label: '预设路线',
    field: 'preTravelLineId',
    component: 'ApiSelect',
    required: true,
    componentProps: ({ formActionType, formModel }) => {

      if (formModel.cityId && formModel.travelDays && formModel.destination) {
        return {
          //multiple: 多选；不填写为单选
          mode: '',
          //请求api,返回结果{ result: { records: [{'id':'1',name:'scott'},{'id':'2',name:'小张'}] }}
          api: () => defHttp.get({ url: '/journey/bsTravelgroupTravelistgroup/getTravelLinesByCityId?pageSize=100&cityId=' + formModel.cityId + '&days=' + formModel.travelDays + '&destination=' + formModel.destination }),
          //数值转成String
          numberToString: false,
          //标题字段
          labelField: 'prelinename',
          //值字段
          valueField: 'id',
          //请求参数
          params: {
            carpoolBus: formModel.carpoolBus
          },
          //返回结果字段
          resultField: 'records'
        }
      }

    },
    /* 	colProps:{
        span:12
      }, */
    dynamicDisabled: ({ values }) => {
      return values.isUpdate == true
    },
  },
  /* 	{
      label: '租户ID',
      field: 'tenantid',
      component: 'Input',
      dynamicRules: ({ model, schema }) => {
        return [
          { required: true, message: '请输入租户ID!' },
        ];
      },
    }, */
  {
    label: '出发日期',
    field: 'startdateStr',
    component: 'DatePicker',
    dynamicRules: ({ model, schema }) => {
      return [
        { required: true, message: '请选择出发日期!' },
      ];
    },
  },
  {
    label: '最多人数',
    field: 'maxUserNum',
    component: 'InputNumber',
    dynamicRules: ({ model, schema }) => {
      return [
        { required: true, message: '请输入最大人数!' },
      ];
    },
  },
  {
    label: '成团人数',
    field: 'groupUserSize',
    component: 'InputNumber',
    dynamicRules: ({ model, schema }) => {
      return [
        { required: true, message: '请输入成团人数！' },
      ];
    },
  },
  {
    label: '虚拟报名数',
    field: 'virtualUserNum',
    component: 'InputNumber',
    dynamicRules: ({ model, schema }) => {
      return [
        { required: true, message: '请输入虚拟报名数!' },
      ];
    },
  },
  {
    label: '合同ID',
    field: 'contractid',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [
        { required: true, message: '请输入合同ID!' },
      ];
    },
  },
  {
    label: '保险ID',
    field: 'insuranceid',
    component: 'Input',
    dynamicRules: ({ model, schema }) => {
      return [
        { required: true, message: '请输入保险ID!' },
      ];
    },
  },
  {
    label: '报名截止时间',
    field: 'expiredateStr',
    component: 'DatePicker',
    componentProps: {
      showTime: true,
      valueFormat: 'YYYY-MM-DD HH:mm:ss'
    },
    dynamicRules: ({ model, schema }) => {
      return [
        { required: true, message: '请输入报名截止日期!' },
      ];
    },
  },

  {
    label: '预选车辆',
    field: 'pretravelcarlist',
    component: 'ApiSelect',
    required: true,
    componentProps: ({ formActionType, formModel }) => {
      if (formModel.travelDays) {
        return {
          //multiple: 多选；不填写为单选
          mode: 'multiple',
          //请求api,返回结果{ result: { records: [{'id':'1',name:'scott'},{'id':'2',name:'小张'}] }}
          api: () => defHttp.get({ url: '//scenic/bsPretravelcarprice/list?daynum=' + formModel.travelDays }),
          //数值转成String
          numberToString: false,
          //标题字段
          labelField: 'leveltitle',
          //值字段
          valueField: 'id',
          //请求参数
          params: {
            carpoolBus: formModel.carpoolBus
          },
          //返回结果字段
          resultField: 'records'
        }
      }

    },
  },
  {
    label: '备注',
    field: 'remark',
    component: 'InputTextArea',
    dynamicRules: ({ model, schema }) => {
      return [
        { required: true, message: '请输入备注!' },
      ];
    },
    colProps: {
      span: 24,
    },
  },
  /* 	{
      label: '其他信息',
      field: 'extinfor',
      component: 'InputTextArea',
      dynamicRules: ({ model, schema }) => {
        return [
          { required: true, message: '请输入其他信息!' },
        ];
      },
    }, */
  /* 	{
      label: '预选车辆',
      field: 'pretravelcarlist',
      component: 'InputTextArea',
      dynamicRules: ({ model, schema }) => {
        return [
          { required: true, message: '请输入预选车辆!' },
        ];
      },
    }, 
    {
      label: '旅游路线',
      field: 'travellineremark',
      component: 'InputTextArea',
      dynamicRules: ({ model, schema }) => {
        return [
          { required: true, message: '请输入旅游路线!' },
        ];
      },
    },*/
  {
    label: '行程简介',
    field: 'msg',
    component: 'JEditor',
    dynamicRules: ({ model, schema }) => {
      return [
        { required: true, message: '请输入旅游路线!' },
      ];
    },
    colProps: {
      span: 24,
    },
  },

  // TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false
  },
];

/**
* 流程表单调用这个方法获取formSchema
* @param param
*/
export function getBpmFormSchema(_formData) : FormSchema[] {
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}